#include "NetworkMessage.h"
#include "TestBase.h"

TestBase::TestBase()
{
	info.Name = "NetworkMessage Test 0";
	info.Category = 0x2100;
	info.CategoryName = "NetworkMessage";
	info.File = __FILE__;
}

bool TestBase::Run()
{
	unsigned char c = 0x01;
	unsigned short s = 0x0123;
	unsigned long l = 0x01234567;
	unsigned long long ll = 0x0123456789abcdef;
	NetworkMessage msg1, msg2;
	msg1.WriteByte(c);
	msg1.WriteWord(s);
	msg1.WriteDoubleWord(l);
	msg1.WriteQuadWord(ll);
	msg2 = msg1;
	unsigned char cO = msg2.ReadByte();
	unsigned short sO = msg2.ReadWord();
	unsigned long lO = msg2.ReadDoubleWord();
	unsigned long long llO = msg2.ReadQuadWord();
	if (c != cO || s != sO || l != lO || ll != llO)
	{
		std::cout << GetTestInfo()->Name << " failure info" << std::endl;
		if (c != cO)
		{
			printf("unsigned char\n");
			printf("Output          :%.2x\n", (unsigned int)(cO));
			printf("Expected output :%.2x", (unsigned int)(c));
			printf("Same?           :%s\n", (c == cO) ? "true" : "false");
		}
		if (s != sO)
		{
			printf("unsigned short\n");
			printf("Output          :%.4x\n", (unsigned int)(sO));
			printf("Expected output :%.4x", (unsigned int)(s));
			printf("Same?           :%s\n", (s == sO) ? "true" : "false");
		}
		if (l != lO)
		{
			printf("unsigned long\n");
			printf("Output          :%.8x\n", lO);
			printf("Expected output :%.8x", l);
			printf("Same?           :%s\n", (l == lO) ? "true" : "false");
		}
		if (ll != llO)
		{
			printf("unsigned long long\n");
			printf("Output          :%.8x%.8x\n", (unsigned int)(llO >> 32), (unsigned int)(llO & 0xFFFFFFFF));
			printf("Expected output :%.8x*.8x", (unsigned int)(ll >> 32), (unsigned int)(ll & 0xFFFFFFFF));
			printf("Same?           :%s\n", (ll == llO) ? "true" : "false");
		}
		return false;
	}
	return true;
}